package org.canda.spring6.resource;

import org.springframework.core.io.FileSystemResource;

import java.io.IOException;
import java.io.InputStream;

/**
 * 访问系统资源
 */
public class FileSystemResourceDemo {
    public static void main(String[] args) {
        loadFileSystemResource("E:\\study\\spring\\reTest.txt");
    }

    public static void loadFileSystemResource(String path){
        FileSystemResource resource = new FileSystemResource(path);
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());
        try {
            InputStream inputStream = resource.getInputStream();
            byte[] data = new byte[1024];
            while(inputStream.read(data) != -1){
                System.out.println(new String(data));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
